<template>
    <view>
        <view v-if="goods != null" class="page_big">
			<!-- #ifdef APP-PLUS -->
			<!-- 右侧icon -->
			<view class="top-share-right-icon">
			    <uni-icons type="redo" size="20" color="#333" class="icon round cp" @tap="popup_share_event"></uni-icons>
			</view>
			<!-- #endif -->
            <!-- 轮播图片 -->
            <swiper
                :indicator-dots="indicator_dots"
                :indicator-color="indicator_color"
                :indicator-active-color="indicator_active_color"
                :autoplay="autoplay"
                :circular="circular"
                class="goods-photo bg-grey"
                v-if="goods_photo.length > 0"
            >
                <block v-for="(item, index) in goods_photo" :key="index">
                    <swiper-item>
                        <image class="swiper-item wh-auto" @tap="goods_photo_view_event" :data-index="index" :src="item.images" mode="aspectFit" />
                    </swiper-item>
                </block>
            </swiper>

            <!-- 视频 -->
            <block v-if="goods.video.length > 0">
                <view v-if="goods_video_is_autoplay" class="goods-video">
                    <video
                        :src="goods.video"
                        :autoplay="goods_video_is_autoplay"
                        :show-center-play-btn="true"
                        :controls="false"
                        :show-play-btn="false"
                        :enable-progress-gesture="false"
                        :show-fullscreen-btn="false"
                    ></video>
                </view>
                <view class="goods-video-submit">
                    <image
                        v-if="!goods_video_is_autoplay"
                        class="goods-video-play"
                        @tap="goods_video_play_event"
                        :src="common_static_url+'video-play-icon.png'"
                        mode="aspectFit"
                    ></image>
                    <image
                        v-if="goods_video_is_autoplay"
                        class="goods-video-close"
                        @tap="goods_video_close_event"
                        :src="common_static_url+'video-close-icon.png'"
                        mode="aspectFit"
                    ></image>
                </view>
            </block>

            <!--拼团横幅-->
            <view class="pintuanbox" :style="'background:url('+groups_static_url+'mini/tiao.png) no-repeat;background-size: 100% 106rpx;'">
                <text class="pin_price_symbol">{{ currency_symbol }}</text>
                <text class="pin_price">{{ goods.min_price }}</text>
                <text v-if="goods.min_price != goods.max_price" class="pin_price_qi">- {{ currency_symbol }}{{ goods.max_price }}</text>
                <view class="rightcc">
                    <text v-if="(goods.original_price || null) != null && goods.original_price != '0.00'" class="original-price">{{lang_info.list_price_old_before}}{{ currency_symbol }}{{ goods.price_preferential }}{{lang_info.list_price_old_after}}</text>
                    <view class="rightcon">
                        <text class="t2">{{ groups_status_text }}</text>
                        <text class="t3">{{lang_info.list_already_buy_before}} {{ goods.sales_count }} {{lang_info.list_already_buy_after}}</text>
                    </view>
                </view>
            </view>

            <!-- 基础息 -->
            <view class="goods-base bg-white spacing-mb">
                <!-- 标题 -->
                <view class="goods-title pr" :style="'color:' + goods.title_color">
                    <text class="t1">{{lang_info.list_need_how_many_before}}{{ goods.num }}{{lang_info.list_need_how_many_after}}</text>
					<text>{{ goods.title }}</text>
					<view class="goods-share tc" @tap="popup_share_event">
						<image :src="groups_static_url+'mini/goods-detail-share-icon.png'" mode="scaleToFill" class="dis-block" />
					</view>
                </view>
                <view class="goods-price">
                    <view class="simple_desc">{{ goods.groups_simple_desc }}</view>
                </view>
            </view>

            <!-- 可参与的团 -->
			<view v-if="tuan_data.length > 0" class="tuan_list oh">
				<view v-if="ispin == 0" class="can_join_tuan_top">{{lang_info.detail_base_tuan_can_join_text}}</view>
				<view v-else class="can_join_tuan_top">{{lang_info.detail_base_tuan_join_text}}</view>
				<view class="tuan_ui">
					<view class="tuan_li li1" v-for="(item, index) in tuan_data" :key="index">
						<view :style="((ispin == 1 && teamid == item.teamid) || ispin == 0) ? '' : 'display:none;'">
							<image :src="item.user.avatar" mode="aspectFill" />
							<view class="whois">{{ item.teamname }}</view>
							<view class="liright">
								<view class="tinfo">
									<view class="v1">
									   <!-- {{lang_info.list_need_how_many_before}}{{ item.items[0].groupsnum }}{{lang_info.list_need_how_many_after}}，-->{{lang_info.detail_base_tuan_need_text}} <text>{{ item.shengyurenshu }}</text> {{lang_info.detail_base_tuan_people_text}}
									</view>
									<view class="v2" v-if="item.items[0].time.status == 1">
										<component-countdown :propHour="item.items[0].time.hours" :propMinute="item.items[0].time.minutes" :propSecond="item.items[0].time.seconds" :propMsecShow="true" propTimeSize="32" propTimePadding="0" propTimeWeight="bold" propTimeBackgroundColor="transparent" propTimeColor="#ffe500" propDsColor="#fff" :propTextTips="lang_info.detail_cutdown_tips_1" :propTextTipsEnd="lang_info.detail_cutdown_tips_2"></component-countdown>
									</view>
								</view>
								<view class="joinbutton" :data-teamid="item.teamid" @tap="buy_join_event">{{lang_info.detail_base_tuan_buy_text}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else class="tuan_list oh">
				<view class="can_join_tuan_top">{{lang_info.detail_base_tuan_noteam_text}}</view>
			</view>

            <view class="wanfa spacing">
                <view class="spacing-nav-title">
                    <text class="line"></text>
                    <text class="text-wrapper">{{lang_info.detail_base_title_wanfa_text}}</text>
                    <view class="seerule" @tap="popup_wanfa_event">{{lang_info.detail_base_title_guize_text}}</view>
                </view>
                <view class="wanfacc weui-flex bg-white">
                    <view class="weui-flex__item">
                        <view class="placeholder">
                            <text>1</text>
                            {{lang_info.detail_base_title_guize_1}}
                        </view>
                    </view>
                    <view class="weui-flex__item">
                        <view class="placeholder">
                            <text>2</text>
                            {{lang_info.detail_base_title_guize_2}}
                        </view>
                    </view>
                    <view class="weui-flex__item">
                        <view class="placeholder">
                            <text>3</text>
                            {{lang_info.detail_base_title_guize_3}}
                        </view>
                    </view>
                    <view class="weui-flex__item">
                        <view class="placeholder">
                            <text>4</text>
                            {{lang_info.detail_base_title_guize_4}}
                        </view>
                    </view>
                </view>
            </view>
			
			<!-- 商品评价 -->
			<view v-if="common_is_show_goods_comments == 1" class="goods-comment margin-top bg-white">
			    <view class="spacing-nav-title margin-bottom-lg" style="margin-right:-20rpx;padding-right: 20rpx;">
			        <text class="line"></text>
			        <text class="text-wrapper">{{lang_info.comment_detail_big_title}}</text>
			        <text class="margin-left-xs">({{goods.comments_count}})</text>
			        <navigator :url="'/pages/fcc/groups/goods-comment/goods-comment?goods_id=' + goods.id" hover-class="none" class="arrow-right padding-right-xxxl cr-grey fr">{{lang_info.comment_detail_rate_text}} {{goods.comments_score.rate}}%</navigator>
			    </view>
			    <view class="border-radius-main padding-main bg-white">
					<!-- 商品数据 -->
					<component-goods-comments :prop-data="goods.comments_data" :propLangInfo="lang_info"></component-goods-comments>
				</view>
			</view>
			
			<!--展示多商户信息-->

            <!-- 商品详情 -->
            <view class="goods-detail spacing">
                <view class="spacing-nav-title">
                    <text class="line"></text>
                    <text class="text-wrapper">{{lang_info.detail_base_title_xiangqing_text}}</text>
                </view>
                <!-- 是否详情展示相册 -->
                <block v-if="common_is_goods_detail_show_photo == 1 && goods_photo.length > 0">
                    <view class="goods-detail-photo bg-white" v-for="(item, index) in goods_photo" :key="index">
                        <image
                            v-if="(item.images || null) != null"
                            @tap="goods_detail_images_view_event"
                            :data-value="item.images"
                            class="wh-auto dis-block"
                            :src="item.images"
                            mode="widthFix"
                        />
                    </view>
                </block>
                <!-- web详情 -->
                <view v-if="common_app_is_use_mobile_detail == 0" class="bg-white">
					<mp-html :content="goods.content_web" />
                </view>
                <!-- 手机独立详情 -->
                <block v-if="common_app_is_use_mobile_detail == 1 && goods_content_app.length > 0">
                    <view class="goods-detail-app bg-white" v-for="(item, index) in goods_content_app" :key="index">
                        <image
                            v-if="(item.images || null) != null"
                            @tap="goods_detail_images_view_event"
                            :data-value="item.images"
                            class="wh-auto dis-block"
                            :src="item.images"
                            mode="widthFix"
                        />

                        <view v-if="(item.content || null) != null" class="content-items">
                            <view v-for="(items, index1) in item.content" :key="index1">{{ items }}</view>
                        </view>
                    </view>
                </block>
            </view>

            <!-- 底线 -->
			<component-bottom-line :propStatus="data_bottom_line_status" :propMsg="lang_info.data_bottom_line_msg"></component-bottom-line>

            <!-- 底部操作 -->
            <view class="goods-buy-nav wh-auto bg-white bottom-line-exclude">
                <view class="shop fl tc" @tap="shop_event">
					<image :src="groups_static_url+'mini/goods-detail-home-icon.png'" mode="scaleToFill" />
                    <text class="dis-block cr-888">{{lang_info.detail_base_home_text}}</text>
                </view>
                <!--<view class="collect fl tc" bindtap="goods_favor_event">
      <image src="{{goods_favor_icon}}" mode="scaleToFill" />
      <text class="dis-block cr-888">{{goods_favor_text}}</text>
    </view>-->
                <view :class="'fr ' + (common_site_type == 1 ? 'exhibition-mode' : '')">
                    <!-- 站点模式 1 展示型 -->
                    <block v-if="common_site_type == 1">
                        <button class="bg-main fl" type="default" @tap="exhibition_submit_event" hover-class="none">{{ nav_submit_text }}</button>
                    </block>

                    <!-- 销售型,自提点,虚拟销售 -->
                    <block v-else>
                        <button class="bg-warning fl" type="default" @tap="oldbuy_submit_event" hover-class="none" :disabled="nav_submit_is_disabled">
                            <text>{{ currency_symbol }}{{ goods.min_original_price }}</text>
                            {{lang_info.detail_base_single_buy_text}}
                        </button>
                        <button class="bg-main fl" type="default" @tap="buy_submit_event" hover-class="none" :disabled="nav_submit_is_disabled">
                            <text>{{ currency_symbol }}{{ goods.min_price }}</text>
                            {{ nav_submit_text }}
                        </button>
                    </block>
                </view>
            </view>

            <!-- 购买弹层 -->
            <component-popup :propShow="popup_status" propPosition="bottom" @onclose="popup_close_event">
                <view class="goods-popup bg-white bottom-line-exclude">
                    <view class="close fr oh">
                        <view class="fr" @tap.stop.prevent="popup_close_event">
                            <icon type="clear" size="20" />
                        </view>
                    </view>
                    <!-- 规格基础信息 -->
                    <view class="goods-popup-base oh br-b">
                        <image :src="goods_spec_base_images" mode="scaleToFill" class="br" />
                        <view class="goods-popup-base-content">
                            <view class="goods-price">
                                <view class="sales-price">{{ currency_symbol }}{{ goods_spec_base_price }}</view>
                                <view v-if="(goods_spec_base_original_price || null) != null && goods_spec_base_original_price > 0" class="original-price">
                                    {{ currency_symbol }}{{ goods_spec_base_original_price }}
                                </view>
                            </view>
                            <view class="inventory">
                                <text class="cr-888">{{lang_info.detail_base_title_kucun_text}}</text>
                                <text class="cr-666">{{ goods_spec_base_inventory }}</text>
                                <text class="cr-888">{{ goods.inventory_unit }}</text>
                            </view>
                        </view>
                    </view>

                    <view class="goods-popup-content">
                        <!-- 商品属性 -->
                        <view v-if="goods_specifications_choose.length > 0" class="goods-attr-choose">
                            <view class="item br-b" v-for="(item, key) in goods_specifications_choose" :key="key">
                                <view class="title">{{ item.name }}</view>

                                <view v-if="item.value.length > 0" class="spec">
                                    <block v-for="(items, keys) in item.value" :key="keys">
										<button @tap.stop="goods_specifications_event" :data-key="key" :data-keys="keys" type="default" size="mini" hover-class="none" :class="items.is_active + ' ' + items.is_dont + ' ' + items.is_disabled">
                                            <image v-if="(items.images || null) != null" :src="items.images" mode="scaleToFill" />
                                            {{ items.name }}
                                        </button>
                                    </block>
                                </view>
                            </view>
                        </view>

                        <!-- 购买数量 -->
                        <view class="goods-buy-number oh">
                            <view class="title fl">{{lang_info.detail_base_title_buynum_text}}</view>
                            <view class="number-content tc oh">
                                <view @tap="goods_buy_number_event" class="number-submit tc cr-888 fl" data-type="0">-</view>
                                <input @blur="goods_buy_number_blur" class="tc cr-888 fl" type="number" :value="temp_buy_number" />
                                <view @tap="goods_buy_number_event" class="number-submit tc cr-888 fl" data-type="1">+</view>
                            </view>
                        </view>
                    </view>
                    <button class="goods-popup-submit bg-main" type="default" @tap.stop.prevent="goods_buy_confirm_event" hover-class="none">{{lang_info.detail_base_enter_btn_text}}</button>
                </view>
            </component-popup>

            <!-- 规则弹层 -->
            <view class="wanfa-popup">
                <component-popup :propShow="popup_wanfa_status" propPosition="bottom" @onclose="popup_wanfa_close_event">
                    <view class="share-popup bg-white bottom-line-exclude">
                        <view class="close fr oh">
                            <view class="fr" @tap.stop.prevent="popup_wanfa_close_event">
                                <icon type="clear" size="20" />
                            </view>
                        </view>
                        <view class="share-popup-content wanfapopup">
                            <view v-if="(goods.guize || null) != null" class="web-html-content">
                                <mp-html :content="goods.guize" />
                            </view>
                        </view>
                    </view>
                </component-popup>
            </view>
			
			<!-- 在线客服 -->
			<component-online-service v-if="common_app_is_online_service == 1" :propIsGoods="false" :propIsNav="true" :propCard="true" :propTitle="goods.title" :propImg="goods.images" :propPath="'/pages/fcc/groups/detail/detail?goods_id='+goods.id" :propChatUrl="(plugins_chat_data == null) ? '' : plugins_chat_data.chat_url"></component-online-service>
			
			<!-- 分享弹窗 -->
			<component-share-popup :diyTheme="diytheme" ref="share"></component-share-popup>
        </view>

        <view v-if="goods == null">
            <!-- 提示信息 -->
            <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
        </view>
		
		<!-- #ifdef APP-PLUS -->
		<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" :permissionID="permissionID"></yk-authpup>
		<!-- #endif -->
    </view>
</template>

<script>
const app = getApp();
// #ifdef APP-PLUS
import ykAuthpup from "@/components/yk-authpup/yk-authpup";
// #endif
import componentPopup from '@/components/popup/popup';
import componentQuickNav from "@/components/quick-nav/quick-nav";
import componentBadge from '@/components/badge/badge';
import componentNoData from "@/components/no-data/no-data";
import componentBottomLine from "@/components/bottom-line/bottom-line";
import componentOnlineService from "@/components/online-service/online-service";
import componentCountdown from "@/pages/fcc/groups/public/countdown";
import componentGoodsComments from '@/pages/fcc/groups/public/goods-comments';
import componentSharePopup from "@/components/share-popup/share-popup";
import {system_base_info} from "@/common/js/common/common";

import { groups_base_info, clear_user_cach } from '@/pages/fcc/groups/public/common.js';
var groups_static_url = app.globalData.get_static_url('groups', true);
var common_static_url = app.globalData.get_static_url('common');
export default {
    components: {
		// #ifdef APP-PLUS
		ykAuthpup,
		// #endif
        componentQuickNav,
        componentPopup,
        componentBadge,
        componentNoData,
        componentBottomLine,
        componentOnlineService,
		componentCountdown,
		componentGoodsComments,
		componentSharePopup
    },
    data() {
        return {
            currency_symbol: app.globalData.currency_symbol(),
			groups_static_url: groups_static_url,
			common_static_url: common_static_url,
            indicator_dots: false,
            indicator_color: '',
            indicator_active_color: '',
            autoplay: true,
            circular: true,
            data_bottom_line_status: false,
            data_list_loding_status: 1,
            data_list_loding_msg: '',
            params: null,
            goods: null,
            goods_photo: [],
            goods_specifications_choose: [],
            goods_content_app: [],
            popup_status: false,
            goods_favor_text: '收藏',
            goods_favor_icon: '/static/images/goods-detail-favor-icon-0.png',
            temp_buy_number: 1,
            buy_event_type: 'buy',
            nav_submit_text: '',
            nav_submit_is_disabled: true,
            groups_status_text: '',
            goods_spec_base_price: 0,
            goods_spec_base_original_price: 0,
            goods_spec_base_inventory: 0,
            goods_spec_base_images: '',
            goods_spec_base_price_old: 0,
            show_field_price_text: null,
            goods_video_is_autoplay: false,
            common_app_is_use_mobile_detail: 1,
            common_is_goods_detail_show_photo: 0,
            popup_share_status: false,
            common_app_is_online_service: 0,
            popup_wanfa_status: false,
            // 海报分享
            common_app_is_poster_share: 0,

            // 优惠劵
            plugins_coupon_data: null,

            // 购物车快捷导航
            quick_nav_cart_count: 0,

            // 站点模式
            common_site_type: 0,

            customer_service_tel: null,

            // 优惠劵领取
            temp_coupon_receive_index: null,

            temp_coupon_receive_value: null,
            tuan_data: [],
            teamid: 0,

            //是否拼着买，分享传值
            ispin: 0,

            temp_attribute_active: {},
            common_app_is_limitedtimediscount: '',

            plugins_limitedtimediscount_data: {
                time: {
                    hours: '',
                    minutes: '',
                    seconds: ''
                },

                desc: {}
            },

            plugins_limitedtimediscount_timer: '',
            plugins_limitedtimediscount_is_show_time: false,
            plugins_limitedtimediscount_time_millisecond: '',
            plugins_limitedtimediscount_timers: '',
            length: 0,
            keys: [],
			permissionID:'',
			// 客服插件
			plugins_chat_data: null,
			// 多商户插件
			plugins_shop_data: null,
			// 自定义分享信息
			share_info: {},
			// 多语言
			lang_info:{},
			common_is_show_goods_comments: 1,
			diytheme:null,
        };
    },
    onLoad(params) {
        // 启动参数处理
        params = app.globalData.launch_params_handle(params); // 参数赋值,初始化
        //params['goods_id']=2;

        this.setData({
            params: params
        });
        //this.init();
    },
    onShow() {
        this.init();
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.init();
    },
    // 页面销毁时执行
    onUnload: function () {
        clearInterval(this.plugins_limitedtimediscount_timer);
        clearInterval(this.plugins_limitedtimediscount_timers);
    },
    methods: {
        // 获取数据列表
        init() {
			// 先获取语言基础信息
			groups_base_info()
			.then(data=>{
				this.init_before(data)
				.then(()=>{
					system_base_info()
					.then(data=>{
						this.sys_init(data);
						this.init_real();
					});
				});
			});
		},
		// 设置系统基础参数
		sys_init(data){
			this.setData({
				diytheme: data.diytheme,
			});
		},
		// 设置本页参数
		init_before(data){
			var self = this;
			return new Promise((resolve, reject) => {
				self.setData({
					lang_info:data,
					currency_symbol: app.globalData.get_config('currency_symbol'),
					common_app_is_online_service: app.globalData.get_config('config.common_app_is_online_service'),
				});
				
				resolve();
			});
		},
		
		// 真正的数据初始化
		init_real(){
			var self = this;
			// 数据初始化
			if ((this.params.ispin || null) == null) {
				this.setData({
					temp_attribute_active: {}
				});
			} else {
				this.setData({
					temp_attribute_active: {},
					ispin: 1,
					teamid: parseInt(this.params.teamid)
				});
			}
			
			console.log('test' + this.ispin + '---' + this.teamid); // 参数校验
			
			if ((this.params.goods_id || null) == null) {
				uni.stopPullDownRefresh();
				this.setData({
					data_bottom_line_status: false,
					data_list_loding_status: 2,
					data_list_loding_msg: self.lang_info.detail_id_is_wrong
				});
			} else {
				uni.showLoading({
					title: self.lang_info.loading_tips
				});
				this.setData({
					data_list_loding_status: 1
				});
				uni.request({
					url: app.globalData.get_request_url('detail', 'index', 'groups'),
					method: 'POST',
					data: {
						goods_id: self.params.goods_id
					},
					dataType: 'json',
					success: (res) => {
						uni.stopPullDownRefresh();
						uni.hideLoading();
						console.log(res);
			
						if (res.data.code == 0) {
							var data = res.data.data;
							self.setData({
								goods: data.goods,
								tuan_data: data.tuan_data,
								indicator_dots: data.goods.photo.length > 1,
								autoplay: data.goods.photo.length > 1,
								goods_photo: data.goods.photo,
								goods_specifications_choose: data.goods.specifications.choose || [],
								goods_content_app: data.goods.content_app || [],
								temp_buy_number: data.goods.buy_min_number || 1,
								goods_favor_text: data.goods.is_favor == 1 ? ' ' : ' ',
								goods_favor_icon: '/images/goods-detail-favor-icon-' + data.goods.is_favor + '.png',
								data_bottom_line_status: true,
								data_list_loding_status: 3,
								goods_spec_base_price: data.goods.price,
								goods_spec_base_original_price: data.goods.original_price,
								goods_spec_base_inventory: data.goods.inventory,
								goods_spec_base_images: data.goods.images,
								goods_spec_base_price_old: data.goods.original_price,
								common_app_is_use_mobile_detail: data.common_app_is_use_mobile_detail || 0,
								common_is_goods_detail_show_photo: data.common_is_goods_detail_show_photo || 0,
								common_app_is_online_service: data.common_app_is_online_service || 0,
								common_app_is_limitedtimediscount: data.common_app_is_limitedtimediscount || 0,
								plugins_limitedtimediscount_data: data.plugins_limitedtimediscount_data || null,
								plugins_coupon_data: data.plugins_coupon_data || null,
								quick_nav_cart_count: data.common_cart_total || 0,
								common_app_is_poster_share: data.common_app_is_poster_share || 0,
								plugins_chat_data: data.plugins_chat_data || null,
								common_is_show_goods_comments: data.common_is_show_goods_comments
							}); 
							
							// 标题
							uni.setNavigationBarTitle({
								title: data.goods.title
							}); 
							
							// 分享配置
							self.setData({
								// 基础自定义分享
								share_info: {
									title: data.goods.seo_title || data.goods.title,
									kds: data.goods.seo_keywords || data.goods.simple_desc,
									desc: data.goods.seo_desc || data.goods.simple_desc,
									path: '/pages/fcc/groups/detail/detail',
									query: 'goods_id=' + data.goods.id,
									img: data.goods.images,
									video: data.goods.video
								}
							});
							
							// 不能选择规格处理
							this.goods_specifications_choose_handle_dont(0); 
							
							// 购买按钮处理
							var nav_submit_text = self.lang_info.detail_nav_submit_text;
			
							var nav_submit_is_disabled = data.goods.is_shelves == 1 && data.goods.inventory > 0 ? false : true;
							var groups_status_text = self.lang_info.detail_groups_status_ing;
			
							if (data.goods.is_shelves != 1) {
								nav_submit_text = self.lang_info.detail_groups_status_down;
								nav_submit_is_disabled = true;
								groups_status_text = self.lang_info.detail_groups_status_down;
							} else {
								if (data.goods.inventory <= 0) {
									nav_submit_text = self.lang_info.detail_groups_status_off;
									nav_submit_is_disabled = true;
									groups_status_text = self.lang_info.detail_groups_status_off;
								}
							} 
							
							// 站点模式 - 是否展示型
							var common_site_type = data.common_site_type || 0;
			
							if (common_site_type == 1) {
								nav_submit_text = self.lang_info.detail_nav_submit_text_2;
							} 
							
							// 数据赋值
							self.setData({
								nav_submit_text: nav_submit_text,
								groups_status_text: groups_status_text,
								nav_submit_is_disabled: nav_submit_is_disabled,
								common_site_type: common_site_type,
								customer_service_tel: data.customer_service_tel || null
							});
						} else {
							self.setData({
								data_bottom_line_status: false,
								data_list_loding_status: 0,
								data_list_loding_msg: res.data.msg
							});
						}
						
						// 分享菜单处理
						app.globalData.page_share_handle(self.share_info);
					},
					fail: () => {
						uni.stopPullDownRefresh();
						uni.hideLoading();
						self.setData({
							data_bottom_line_status: false,
							data_list_loding_status: 2,
							data_list_loding_msg: self.lang_info.request_data_error_tips
						});
						app.globalData.showToast(self.lang_info.request_data_error_tips);
					}
				});
			}
        },

        // 不能选择规格处理
        goods_specifications_choose_handle_dont(key) {
            var temp_data = this.goods_specifications_choose || [];

            if (temp_data.length <= 0) {
                return false;
            } // 是否不能选择

            for (var i in temp_data) {
                for (var k in temp_data[i]['value']) {
                    if (i > key) {
                        temp_data[i]['value'][k]['is_dont'] = 'spec-dont-choose';
                        temp_data[i]['value'][k]['is_disabled'] = '';
                        temp_data[i]['value'][k]['is_active'] = '';
                    } // 当只有一个规格的时候

                    if (key == 0 && temp_data.length == 1) {
                        if ((temp_data[i]['value'][k]['is_only_level_one'] || null) != null && (temp_data[i]['value'][k]['inventory'] || 0) <= 0) {
                            temp_data[i]['value'][k]['is_disabled'] = 'spec-items-disabled';
                        } else {
                            temp_data[i]['value'][k]['is_disabled'] = '';
                        }
                    }
                }
            }

            this.setData({
                goods_specifications_choose: temp_data
            });
        },

        // 进入商品属性事件
        good_attribute_nav_event(e) {
            app.globalData.url_open('/pages/goods-attribute/goods-attribute?data=' + JSON.stringify(this.goods_attribute_show));
        },

        // 购买弹层关闭
        popup_close_event(e) {
            this.setData({
                popup_status: false
            });
        },

        // 进入店铺
        shop_event(e) {
            app.globalData.url_open('/pages/fcc/groups/index/index');
        },

        // 加入购物车
        cart_submit_event(e) {
            this.setData({
                popup_status: true,
                buy_event_type: 'cart'
            });
        },

        // 原价购买
        oldbuy_submit_event(e) {
            //this.setData({ popup_status: true, buy_event_type: 'oldbuy'});
            //跳转去原商品页
            app.globalData.url_open('/pages/goods-detail/goods-detail?goods_id=' + this.goods.goods_id);
        },

        // 参团购买
        buy_join_event(e) {
            var teamid = e.currentTarget.dataset.teamid;
            this.setData({
                popup_status: true,
                buy_event_type: 'buy',
                teamid: teamid
            });
        },

        // 立即购买
        buy_submit_event(e) {
			this.setData({
			    popup_status: true,
			    buy_event_type: 'buy',
			    teamid: 0
			});
			// 取消从底部参团的设计
            /*if (parseInt(this.ispin) > 0) {
                this.setData({
                    popup_status: true,
                    buy_event_type: 'buy'
                });
            } else {
                this.setData({
                    popup_status: true,
                    buy_event_type: 'buy',
                    teamid: 0
                });
            }*/
        },

        // 收藏事件
        goods_favor_event(e) {
            var user = app.globalData.get_user_info(this, 'goods_favor_event');

            if (user != false) {
				uni.showLoading({
					title: '处理中...'
				});
				uni.request({
					url: app.globalData.get_request_url('favor', 'index', 'groups'),
					method: 'POST',
					data: {
						id: this.goods.id
					},
					dataType: 'json',
					success: (res) => {
						uni.hideLoading();

						if (res.data.code == 0) {
							this.setData({
								'goods.is_favor': res.data.data.status,
								goods_favor_text: res.data.data.text,
								goods_favor_icon: '/images/goods-detail-favor-icon-' + res.data.data.status + '.png'
							});
							app.globalData.showToast(res.data.msg, 'success');
						} else {
							if (app.globalData.is_login_check(res.data, this, 'goods_favor_event')) {
								app.globalData.showToast(res.data.msg);
							}
						}
					},
					fail: () => {
						uni.hideLoading();
						app.globalData.showToast(this.lang_info.request_data_error_tips);
					}
				});
            }
        },

        // 加入购物车事件
        goods_cart_event(spec) {
            var user = app.globalData.get_user_info(this, 'goods_buy_confirm_event');

            if (user != false) {
				uni.showLoading({
					title:this.lang_info.loading_tips
				});
				uni.request({
					url: app.globalData.get_request_url('save', 'index', 'groups'),
					method: 'POST',
					data: {
						goods_id: this.goods.id,
						stock: this.temp_buy_number,
						spec: JSON.stringify(spec)
					},
					dataType: 'json',
					success: (res) => {
						uni.hideLoading();

						if (res.data.code == 0) {
							this.setData({
								quick_nav_cart_count: res.data.data
							});
							this.popup_close_event();
							app.globalData.showToast(res.data.msg, 'success');
						} else {
							if (app.globalData.is_login_check(res.data, this, 'goods_buy_confirm_event')) {
								app.globalData.showToast(res.data.msg);
							}
						}
					},
					fail: () => {
						uni.hideLoading();
						app.globalData.showToast(this.lang_info.request_data_error_tips);
					}
				});
            }
        },

        // 规格事件
        goods_specifications_event(e) {
            var key = e.currentTarget.dataset.key || 0;
            var keys = e.currentTarget.dataset.keys || 0;
            var temp_data = this.goods_specifications_choose;
            var temp_images = this.goods_spec_base_images; // 不能选择和禁止选择跳过

            if ((temp_data[key]['value'][keys]['is_dont'] || null) == null && (temp_data[key]['value'][keys]['is_disabled'] || null) == null) {
                // 规格选择
                for (var i in temp_data) {
                    for (var k in temp_data[i]['value']) {
                        if ((temp_data[i]['value'][k]['is_dont'] || null) == null && (temp_data[i]['value'][k]['is_disabled'] || null) == null) {
                            if (key == i) {
                                if (keys == k && (temp_data[i]['value'][k]['is_active'] || null) == null) {
                                    temp_data[i]['value'][k]['is_active'] = 'spec-active';

                                    if ((temp_data[i]['value'][k]['images'] || null) != null) {
                                        temp_images = temp_data[i]['value'][k]['images'];
                                    }
                                } else {
                                    temp_data[i]['value'][k]['is_active'] = '';
                                }
                            }
                        }
                    }
                }

                this.setData({
                    goods_specifications_choose: temp_data,
                    goods_spec_base_images: temp_images,
                    temp_buy_number: this.goods.buy_min_number || 1
                }); // 不能选择规格处理

                this.goods_specifications_choose_handle_dont(key); // 获取下一个规格类型

                this.get_goods_specifications_type(key); // 获取规格详情

                this.get_goods_specifications_detail();
            }
        },

        // 获取下一个规格类型
        get_goods_specifications_type(key) {
            var temp_data = this.goods_specifications_choose;
            var active_index = key + 1;
            var sku_count = temp_data.length;

            if (active_index <= 0 || active_index >= sku_count) {
                return false;
            } // 获取规格值

            var spec = [];

            for (var i in temp_data) {
                for (var k in temp_data[i]['value']) {
                    if ((temp_data[i]['value'][k]['is_active'] || null) != null) {
                        spec.push({
                            type: temp_data[i]['name'],
                            value: temp_data[i]['value'][k]['name']
                        });
                        break;
                    }
                }
            }

            if (spec.length <= 0) {
                return false;
            } // 获取数据

            uni.request({
                url: app.globalData.get_request_url('spectype', 'index', 'groups'),
                method: 'POST',
                data: {
                    id: this.goods.id,
                    spec: JSON.stringify(spec)
                },
                dataType: 'json',
                success: (res) => {
                    if (res.data.code == 0) {
                        var spec_count = spec.length;
                        var index = spec_count > 0 ? spec_count : 0;

                        if (index < sku_count) {
                            for (var i in temp_data) {
                                for (var k in temp_data[i]['value']) {
                                    if (index == i) {
                                        temp_data[i]['value'][k]['is_dont'] = '';
                                        var temp_value = temp_data[i]['value'][k]['name'];
                                        var temp_status = false;

                                        for (var t in res.data.data) {
                                            if (res.data.data[t] == temp_value) {
                                                temp_status = true;
                                                break;
                                            }
                                        }

                                        if (temp_status == true) {
                                            temp_data[i]['value'][k]['is_disabled'] = '';
                                        } else {
                                            temp_data[i]['value'][k]['is_disabled'] = 'spec-items-disabled';
                                        }
                                    }
                                }
                            }

                            this.setData({
                                goods_specifications_choose: temp_data
                            });
                        }
                    } else {
                        app.globalData.showToast(res.data.msg);
                    }
                },
                fail: () => {
                    app.globalData.showToast(this.lang_info.request_data_error_tips);
                }
            });
        },

        // 获取规格详情
        get_goods_specifications_detail() {
            // 是否全部选中
            var temp_data = this.goods_specifications_choose;
            var sku_count = temp_data.length;
            var active_count = 0; // 获取规格值

            var spec = [];

            for (var i in temp_data) {
                for (var k in temp_data[i]['value']) {
                    if ((temp_data[i]['value'][k]['is_active'] || null) != null) {
                        active_count++;
                        spec.push({
                            type: temp_data[i]['name'],
                            value: temp_data[i]['value'][k]['name']
                        });
                        break;
                    }
                }
            }

            if (spec.length <= 0 || active_count < sku_count) {
                this.setData({
                    goods_spec_base_price: this.goods.price,
                    goods_spec_base_price_old: this.goods.original_price,
                    goods_spec_base_original_price: this.goods.original_price,
                    goods_spec_base_inventory: this.goods.inventory
                });
                return false;
            } // 获取数据

            uni.request({
                url: app.globalData.get_request_url('specdetail', 'index', 'groups'),
                method: 'POST',
                data: {
                    id: this.goods.id,
                    spec: JSON.stringify(spec)
                },
                dataType: 'json',
                success: (res) => {
                    if (res.data.code == 0) {
                        this.setData({
                            goods_spec_base_price: res.data.data.price,
                            goods_spec_base_price_old: res.data.data.original_price,
                            goods_spec_base_original_price: res.data.data.original_price,
                            goods_spec_base_inventory: res.data.data.inventory
                        });
                    } else {
                        app.globalData.showToast(res.data.msg);
                    }
                },
                fail: () => {
                    app.globalData.showToast(this.lang_info.request_data_error_tips);
                }
            });
        },

        // 数量输入事件
        goods_buy_number_blur(e) {
            var buy_number = parseInt(e.detail.value) || 1;
            this.setData({
                temp_buy_number: buy_number
            });
            this.goods_buy_number_func(buy_number);
        },

        // 数量操作事件
        goods_buy_number_event(e) {
            var type = parseInt(e.currentTarget.dataset.type) || 0;
            var temp_buy_number = parseInt(this.temp_buy_number);

            if (type == 0) {
                var buy_number = temp_buy_number - 1;
            } else {
                var buy_number = temp_buy_number + 1;
            }

            this.goods_buy_number_func(buy_number);
        },

        // 数量处理方法
        goods_buy_number_func(buy_number) {
            var buy_min_number = parseInt(this.goods.buy_min_number) || 1;
            var buy_max_number = parseInt(this.goods.buy_max_number) || 0;
            var buy_max_limit = parseInt(this.goods.buy_max_limit) || 0;
            var inventory = parseInt(this.goods_spec_base_inventory);
            var inventory_unit = this.goods.inventory_unit;

            if (buy_number < buy_min_number) {
                buy_number = buy_min_number;

                if (buy_min_number > 1) {
                    app.globalData.showToast(this.lang_info.detail_limit_buy_text + buy_min_number + inventory_unit);
                }
            }

            if (buy_max_number > 0 && buy_number > buy_max_number) {
                buy_number = buy_max_number;
                app.globalData.showToast(this.lang_info.detail_most_buy_text + buy_max_number + inventory_unit);
            }

            if (buy_max_limit > 0) {
                // 购买次数限制，查询该会员是否已经购买的超过限次
                uni.request({
                    url: app.globalData.get_request_url('isbuymaxlimit', 'index', 'groups'),
                    method: 'POST',
                    data: {
                        id: this.goods.id,
                        buy_max_limit: buy_max_limit
                    },
                    dataType: 'json',
                    success: (res) => {
                        if (res.data.code == 0) {
                            // 可以继续下单
                        } else {
                            app.globalData.showToast(this.lang_info.detail_can_not_order_text + buy_max_limit + this.lang_info.detail_can_not_times_text);
                        }
                    },
                    fail: () => {
                        app.globalData.showToast(this.lang_info.request_data_error_tips);
                    }
                });
            }

            if (buy_number > inventory) {
                buy_number = inventory;
                app.globalData.showToast(this.lang_info.detail_base_stock_tips + inventory + inventory_unit);
            }

            this.setData({
                temp_buy_number: buy_number
            });
        },

        // 确认
        goods_buy_confirm_event(e) {
            var user = app.globalData.get_user_info(this, 'goods_buy_confirm_event');
			var self = this;
            if (user != false) {
				// 属性
				var temp_data = this.goods_specifications_choose;
				var sku_count = temp_data.length;
				var active_count = 0;
				var spec = [];

				if (sku_count > 0) {
					for (var i in temp_data) {
						for (var k in temp_data[i]['value']) {
							if ((temp_data[i]['value'][k]['is_active'] || null) != null) {
								active_count++;
								spec.push({
									"type": temp_data[i]['name'],
									"value": temp_data[i]['value'][k]['name']
								});
							}
						}
					}

					if (active_count < sku_count) {
						app.globalData.showToast(this.lang_info.detail_base_spec_tips);
						return false;
					}
				}
				
				var self = this;
				
				// 下单前检测
				uni.showLoading({
					title: this.lang_info.detail_base_jiaoyan_tips
				});
				uni.request({
					url: app.globalData.get_request_url('checkteam', 'index', 'groups'),
					method: 'POST',
					data: {
						goods_id: self.goods.id,
						teamid: self.teamid
					},
					dataType: 'json',
					success: (res) => {
						uni.hideLoading();
						uni.stopPullDownRefresh();console.log(res);
						if (res.data.code == 0) {
							// 此时允许继续
							// 操作类型
							switch (self.buy_event_type) {
								case 'buy':
									// 进入订单确认页面
									var data = {
										buy_type: 'goods',
										goods_id: self.goods.id,
										stock: self.temp_buy_number,
										spec: JSON.stringify(spec),
										buy_style: 'buy',
										teamid: self.teamid
									};
									app.globalData.url_open('/pages/fcc/groups/buy/buy?data=' + encodeURIComponent(JSON.stringify(data)));
									self.popup_close_event();
									break;
							
								case 'cart':
									self.goods_cart_event(spec);
									break;
							
								default:
									app.globalData.showToast(this.lang_info.detail_base_buy_operation_tips);
							}
						} else {
							// 有提示信息，则关闭规格选择弹窗，同时根据返回值，进行业务处理
							if(res.data.code == 888){
								// 重置从分享进来的直接拼着买，让其变成正常进来的，可参团，可开团
								self.setData({
									ispin: 0
								});
							}
							// 如果是前端有登录信息，后端session已被清理缓存，这此处处理掉前端缓存，重新授权
							if(res.data.code == -400){
								clear_user_cach().then(()=>{
									self.goods_buy_confirm_event(e);
								});
								return false;
							}
							self.popup_close_event();
							app.globalData.showToast(res.data.msg);
						}
					},
					fail: () => {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						app.globalData.showToast(this.lang_info.request_data_error_tips);
					}
				});
            }
        },

        // 详情图片查看
        goods_detail_images_view_event(e) {
            var value = e.currentTarget.dataset.value || null;

            if (value != null) {
				if(app.globalData.is_android())
				{
					var self = this;
					uni.previewImage({
					    current: value,
					    urls: [value],
						longPressActions: {
							itemList: [self.$t('fengcheche.fcctips.t9')],
							success: function(data) {
								uni.closePreviewImage();
								self.permissionID = 'WRITE_EXTERNAL_STORAGE';
								setTimeout(()=>{
									self.$refs['authpup'].open(value);
								},500);
							},
							fail: function(err) {
								console.log(err.errMsg);
							}
						}
					});
				}else{
					uni.previewImage({
					    current: value,
					    urls: [value],
					});
				}
            }
        },

        // 商品相册图片查看
        goods_photo_view_event(e) {
            var index = e.currentTarget.dataset.index;
            var all = [];

            for (var i in this.goods_photo) {
                all.push(this.goods_photo[i]['images']);
            }
			if(app.globalData.is_android())
			{
				var self = this;
				uni.previewImage({
				    current: all[index],
				    urls: all,
					longPressActions: {
						itemList: [self.$t('fengcheche.fcctips.t9')],
						success: function(data) {
							uni.closePreviewImage();
							self.permissionID = 'WRITE_EXTERNAL_STORAGE';
							setTimeout(()=>{
								self.$refs['authpup'].open(all[index]);
							},500);
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}else{
				uni.previewImage({
				    current: all[index],
				    urls: all
				});
			}
        },

        // 视频播放
        goods_video_play_event(e) {
            this.setData({
                goods_video_is_autoplay: true
            });
        },

        // 视频关闭
        goods_video_close_event(e) {
            this.setData({
                goods_video_is_autoplay: false
            });
        },
	
		// 分享开启弹层
		popup_share_event(e) {
		    if ((this.$refs.share || null) != null) {
		        this.$refs.share.init({
		            status: true,
		            share_info: this.share_info,
					is_goods_poster: this.common_app_is_poster_share,
					goods_id: this.goods.id,
					plugins_request: app.globalData.get_request_url('goodsposter', 'index', 'groups'),
		        });
		    }
		},

        // 玩法开启弹层
        popup_wanfa_event(e) {
            this.setData({
                popup_wanfa_status: true
            });
        },

        // 玩法弹层关闭
        popup_wanfa_close_event(e) {
            this.setData({
                popup_wanfa_status: false
            });
        },

        // 显示秒杀插件-倒计时
        plugins_limitedtimediscount_countdown() {
            // 销毁之前的任务
            clearInterval(this.plugins_limitedtimediscount_timer);
            clearInterval(this.plugins_limitedtimediscount_timers); // 定时参数

            var status = this.plugins_limitedtimediscount_data.time.status || 0;
            var msg = this.plugins_limitedtimediscount_data.time.msg || '';
            var hours = parseInt(this.plugins_limitedtimediscount_data.time.hours) || 0;
            var minutes = parseInt(this.plugins_limitedtimediscount_data.time.minutes) || 0;
            var seconds = parseInt(this.plugins_limitedtimediscount_data.time.seconds) || 0;
            var self = this;

            if (status == 1) {
                // 秒
                var timer = setInterval(function () {
                    if (seconds <= 0) {
                        if (minutes > 0) {
                            minutes--;
                            seconds = 59;
                        } else {
                            if (hours > 0) {
                                hours--;
                                minutes = 59;
                                seconds = 59;
                            }
                        }
                    } else {
                        seconds--;
                    }

                    self.setData({
                        'plugins_limitedtimediscount_data.time.hours': hours < 10 ? '0' + hours : hours,
                        'plugins_limitedtimediscount_data.time.minutes': minutes < 10 ? '0' + minutes : minutes,
                        'plugins_limitedtimediscount_data.time.seconds': seconds < 10 ? '0' + seconds : seconds,
                        plugins_limitedtimediscount_timer: timer
                    });

                    if (hours <= 0 && minutes <= 0 && seconds <= 0) {
                        // 停止时间
                        clearInterval(timer); // 活动已结束

                        self.setData({
                            'plugins_limitedtimediscount_data.desc': self.lang_info.request_data_error_tips,
                            plugins_limitedtimediscount_is_show_time: false
                        });
                    }
                }, 1000); // 毫秒

                var count = 0;
                var timers = setInterval(function () {
                    count++;
                    self.setData({
                        plugins_limitedtimediscount_time_millisecond: count
                    });

                    if (count > 9) {
                        count = 0;
                    }

                    if (self.plugins_limitedtimediscount_is_show_time == false) {
                        clearInterval(timers);
                    }
                }, 100);
                self.setData({
                    plugins_limitedtimediscount_timers: timers
                });
            } else {
                // 活动已结束
                self.setData({
                    'plugins_limitedtimediscount_data.desc': msg,
                    plugins_limitedtimediscount_is_show_time: false
                });
            }
        },

        // 优惠劵领取事件
        coupon_receive_event(e) {
            // 参数处理
            if ((e || null) == null) {
                var index = this.temp_coupon_receive_index;
                var value = this.temp_coupon_receive_value;
            } else {
                var index = e.currentTarget.dataset.index;
                var value = e.currentTarget.dataset.value;
                this.setData({
                    temp_coupon_receive_index: index,
                    temp_coupon_receive_value: value
                });
            } // 登录校验

            var user = app.globalData.get_user_info(this, 'coupon_receive_event', e);

            if (user != false) {
				var self = this;
				var temp_list = this.plugins_coupon_data.data;

				if (temp_list[index]['is_operable'] != 0) {
					uni.showLoading({
						title: self.lang_info.loading_tips
					});
					uni.request({
						url: app.globalData.get_request_url('receive', 'coupon', 'coupon'),
						method: 'POST',
						data: {
							coupon_id: value
						},
						dataType: 'json',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						success: (res) => {
							uni.hideLoading();

							if (res.data.code == 0) {
								app.globalData.showToast(res.data.msg, 'success');

								if (self.plugins_coupon_data.base != null && self.plugins_coupon_data.base.is_repeat_receive != 1) {
									temp_list[index]['is_operable'] = 0;
									temp_list[index]['is_operable_name'] = self.lang_info.detail_base_coupon_tips;
									self.setData({
										'plugins_coupon_data.data': temp_list
									});
								}
							} else {
								if (app.globalData.is_login_check(res.data, self, 'coupon_receive_event')) {
									app.globalData.showToast(res.data.msg);
								}
							}
						},
						fail: () => {
							uni.hideLoading();
							app.globalData.showToast(this.lang_info.request_data_error_tips);
						}
					});
				}
            }
        },
		// #ifdef APP-PLUS
		//用户授权权限后的回调
		changeAuth(e){
			if(this.permissionID == 'WRITE_EXTERNAL_STORAGE')
			{
				// 直接下载
				app.globalData.save_image_by_url(e);
			}else{
				app.globalData.call_tel(this.customer_service_tel);
			}
		},
		// #endif
        // 展示型事件
        exhibition_submit_event(e) {
			if(app.globalData.is_android())
			{
				this.permissionID = 'CALL_PHONE';
				setTimeout(()=>{
					this.$refs['authpup'].open();
				},500);
			}else{
				app.globalData.call_tel(this.customer_service_tel);
			}
        }
    }
};
</script>
<style>
@import './detail.css';
</style>
